$(function() {
		$(window).history(function(e,hash) {
			if(hash == '') {
				hash = 'Default Page';
			}
			//alert('Navigate to : ' + hash || 'Default Page');
		});

		/* navigation occurs */
		$('#shop_list').historyadd(function(e,c,p) {
			if(c.charAt(0)=='c')
			{
				c = c.substring(1);
				$.ajax({
					url: c,
					cache: false,
					success: function(data) {
						$('#shop_list').html(data);
						handle_shoplist();
					}
				});
				clicked = $("a[href='"+c+"']");
				clicked.parent().siblings().removeClass('active');
				clicked.parent().addClass('active');
			}
		});

		/* when the back or previous button is clicked */
		$('#shop_list').history(function(e,c,p) {
			if(c == '') {
				$('#shop_list').html('Default');	
				c = '/outland/list/ajaxHtml/shop/1';

				clicked = $("a[href='"+c+"']");
				clicked.parent().siblings().removeClass('active');
				clicked.parent().addClass('active');
			}
			else if(c.charAt(0)=='c') {
				c = c.substring(1);

				$.ajax({
					url: c,
					cache: false,
					success: function(data) {
						$('#shop_list').html(data);
						handle_shoplist();
					}
				});
				clicked = $("a[href='"+c+"']");
				clicked.parent().siblings().removeClass('active');
				clicked.parent().addClass('active');
			}
	
		});
		
		/* navigation occurs */
		$('#menulist tbody').historyadd(function(e,c,p) {
			if(c.charAt(0)=='s')
			{
				c = c.substring(1);
				$.ajax({
					url: c,
					cache: false,
					success: function(data) {
						$('#menulist tbody').html(data);
						addCartHandler();
					}
				});
			}
			else
			{
				$('#menulist tbody').html('');
			}

		});

		/* when the back or previous button is clicked */
		$('#menulist tbody').history(function(e,c,p) {
			if(c=='' || c.charAt(0) == 'c')
			{
				$('#menulist tbody').html('');
			}
			else if(c.charAt(0)=='s')
			{
				c = c.substring(1);
				$.ajax({
					url: c,
					cache: false,
					success: function(data) {
						$('#menulist tbody').html(data);
						addCartHandler();
					}
				});
			}
		});
		


		var initial = $.history.getCurrent();
		if(initial == '') {
			initial = 'Default';
		}

		$('#shop_list').html(initial);
		
});
